#include <stdio.h>

int is_in_net(unsigned char *ip,unsigned char *netip,unsigned char *mask)//函数：判断 IP是否在网络地址和掩码范围内
{
    //遍历IP地址的每个字节
    for(int i=0;i<4;i++)
	{
        //将IP地址、网络地址和掩码按位与运算
        if((ip[i]&mask[i])!=(netip[i]&mask[i])) return 0;//如果不匹配，返回0
    }
    return 1;//如果所有字节都匹配，返回 1
}


int main()//测试函数
{
    //测试用例1
    unsigned char ip1[4]={192,168,1,10};
    unsigned char netip1[4]={192,168,1,0};
    unsigned char mask1[4]={255,255,255,0};
    printf("测试用例1: %s\n",is_in_net(ip1,netip1,mask1)?"匹配":"不匹配");

    //测试用例2
    unsigned char ip2[4]={192,168,2,10};
    unsigned char netip2[4]={192,168,1,0};
    unsigned char mask2[4]={255,255,255,0};
    printf("测试用例2: %s\n",is_in_net(ip2,netip2,mask2)?"匹配":"不匹配");

    //测试用例3
    unsigned char ip3[4]={10,0,0,1};
    unsigned char netip3[4]={10,0,0,0};
    unsigned char mask3[4]={255,0,0,0};
    printf("测试用例3: %s\n",is_in_net(ip3,netip3,mask3)?"匹配":"不匹配");

    return 0;
}